package com.bybops.app

import android.graphics.Color
import android.graphics.Rect
import android.support.multidex.MultiDexApplication
import baseproject.com.mybaseproject.utils.DisplayUtil
import com.bybops.model.bean.User
import com.bybops.utils.GsonUtils
import com.bybops.utils.SPUtils
import com.inuker.bluetooth.library.BluetoothContext
import com.uuzuche.lib_zxing.activity.ZXingLibrary
import org.jaaksi.pickerview.picker.BasePicker
import org.jaaksi.pickerview.widget.DefaultCenterDecoration
import org.jaaksi.pickerview.widget.PickerView





class MyApplication : MultiDexApplication() {
    companion object {
        var instance: MyApplication? = null
            private set
    }
    override fun onCreate() {
        super.onCreate()
        instance = this
        initAccessToken()
        // 建议在application中初始化picker 默认属性实现全局设置
        initDefaultPicker()
        //初始化文件
        AppConstant.initFileDir()
        //初始化 扫码
        ZXingLibrary.initDisplayOpinion(this)
        /*蓝牙初始化*/
        BluetoothContext.set(this)
    }

    /**
     * 初始化token
     */
    private fun initAccessToken() {
        mAccessToken = SPUtils.get(AppConstant.Access_Token , "") as String
        var userInfo = SPUtils.get(AppConstant.userInfo , "") as String
        var user = GsonUtils.parseJsonWithGson(userInfo , User::class.java)
        if (user != null){
            mUser = user
        }
    }

    private fun initDefaultPicker() {
        // 利用修改静态默认属性值，快速定制一套满足自己app样式需求的Picker.
        // BasePickerView
        PickerView.sDefaultVisibleItemCount = 3
        PickerView.sDefaultItemSize = 50
        PickerView.sDefaultIsCirculation = false

        // PickerView
        PickerView.sOutTextSize = 18
        PickerView.sCenterTextSize = 18
        PickerView.sCenterColor = Color.parseColor("#5AAA9E")
        PickerView.sOutColor = Color.GRAY
        // BasePicker
        val padding = DisplayUtil.dip2px(this, 20.toFloat())
        BasePicker.sDefaultPaddingRect = Rect(padding, padding, padding, padding)
        BasePicker.sDefaultPickerBackgroundColor = Color.WHITE
        // 自定义 TopBar
//        BasePicker.sDefaultTopBarCreator = BasePicker.IDefaultTopBarCreator { parent -> CustomTopBar(parent) }
        // DefaultCenterDecoration
        DefaultCenterDecoration.sDefaultLineWidth = 1.toFloat()
        DefaultCenterDecoration.sDefaultLineColor = Color.parseColor("#5AAA9E")
        //DefaultCenterDecoration.sDefaultDrawable = new ColorDrawable(Color.WHITE);
//        var leftMargin = DisplayUtil.dip2px(this, 10.toFloat())
//        var topMargin = DisplayUtil.dip2px(this, 2.toFloat())
//        DefaultCenterDecoration.sDefaultMarginRect = Rect(leftMargin, -topMargin, leftMargin, -topMargin)

    }

    /*************个人信息配置****************/
    var mUser : User? = null
    var mAccessToken = ""
    fun setUser(user : User){
        mAccessToken = user.access_token
        mUser = user
    }
    fun getUser() : User?{ return mUser }
}